package cn.bfay.lion.util;

import java.math.BigDecimal;

/**
 * NumberUtils.
 *
 * @author wangjiannan
 * @since 2019/11/13
 */
public class NumberUtils {
    /**
     * 返回大的那个.
     *
     * @return double
     */
    public static double getMaxDouble(double double1, double double2) {
        BigDecimal data1 = new BigDecimal(double1);
        BigDecimal data2 = new BigDecimal(double2);
        if (data1.compareTo(data2) > 0) {
            return double1;
        } else {
            return double2;
        }
    }

    /**
     * 返回小的那个.
     *
     * @return double
     */
    public static double getMinDouble(double double1, double double2) {
        BigDecimal data1 = new BigDecimal(double1);
        BigDecimal data2 = new BigDecimal(double2);
        if (data1.compareTo(data2) < 0) {
            return double1;
        } else {
            return double2;
        }
    }

    /**
     * double是否相等.
     *
     * @return double
     */
    public static boolean doubleEquals(double double1, double double2) {
        BigDecimal data1 = new BigDecimal(double1);
        BigDecimal data2 = new BigDecimal(double2);
        if (data1.compareTo(data2) == 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * double1 < double2 return true or (>=)false.
     *
     * @return double
     */
    public static boolean doubleLt(double double1, double double2) {
        BigDecimal data1 = new BigDecimal(double1);
        BigDecimal data2 = new BigDecimal(double2);
        return data1.compareTo(data2) < 0;
    }

    /**
     * double1 <= double2 return true or (>)false.
     *
     * @return double
     */
    public static boolean doubleLtEquals(double double1, double double2) {
        BigDecimal data1 = new BigDecimal(double1);
        BigDecimal data2 = new BigDecimal(double2);
        return data1.compareTo(data2) <= 0;
    }

    /**
     * double1 > double2 return true or (<=)false.
     *
     * @return double
     */
    public static boolean doubleGt(double double1, double double2) {
        BigDecimal data1 = new BigDecimal(double1);
        BigDecimal data2 = new BigDecimal(double2);
        return data1.compareTo(data2) > 0;
    }

    /**
     * double1 >= double2 return true or (<)false.
     *
     * @return double
     */
    public static boolean doubleGtEquals(double double1, double double2) {
        BigDecimal data1 = new BigDecimal(double1);
        BigDecimal data2 = new BigDecimal(double2);
        return data1.compareTo(data2) >= 0;
    }
}
